<?php
/**
 * GlobalPath.php	set include path
 *
 * @package		
 * @Copyright	(c) All rights reserved
 * @Author		skyCrack <skyCrack@126.com>
 * @Version		$Id$
 */

class GlobalPath {
	private static $incPath;

	//set include_path
	public static function setPath($root = WEBSITE_ROOT, $subPath = '') {
		$appDirs = array('.', '', 'lib');

		if ( empty($subPath) ) {
			/**
			 * @todo notion
			 */
		} elseif ( is_array($subPath) ) {
			$appDirs = array_merge($appDirs, $subPath);
		} elseif ( is_string($subPath) ) {
			$appDirs[]	=	$subPath;
		}
		
		
		self::$incPath	=	self::mapToStr($root, $appDirs);
		set_include_path(self::$incPath);
	}

	public static function appendPath($path, $root = WEBSITE_ROOT) {
		$path = get_include_path() . PATH_SEPARATOR . $root . DIRECTORY_SEPARATOR . $path;

		set_include_path($path);
	}

	public static function getPath() {
		return get_include_path();
	}

	private static function mapToStr($root = WEBSITE_ROOT, $appDirs = array('.', 'lib')) {
		$path = '';

		if ( in_array('.', $appDirs) ) {
			$path .= '.' . PATH_SEPARATOR;
			$appDirs = array_diff($appDirs, array('.'));
		}

		foreach ( $appDirs as $item )
			$path .= $root . DIRECTORY_SEPARATOR . $item . PATH_SEPARATOR;

		return substr($path, 0, -1);
	}
}
?>